/**
* @author:kellen
* @contact:xiekellen@hotmail.com
* @company:achivo-gz
* @created on:
* @modified on:
*/

package com.sasis.dao.ibatis;

import java.util.List;

import com.sasis.dao.ibatis.BaseDaoiBATIS;
import com.sasis.model.FlightTransferProtect;
import com.sasis.dao.FlightTransferProtectDao;

import org.springframework.orm.ObjectRetrievalFailureException;

public class FlightTransferProtectDaoiBatis extends BaseDaoiBATIS implements FlightTransferProtectDao {

    /**
     * @see com.sasis.dao.FlightTransferProtectDao#getFlightTransferProtects(com.sasis.model.FlightTransferProtect)
     */
    public List getFlightTransferProtects(final FlightTransferProtect flightTransferProtect) {
          return getSqlMapClientTemplate().queryForList("getFlightTransferProtects", flightTransferProtect);
    }

    /**
     * @see com.sasis.dao.FlightTransferProtectDao#getFlightTransferProtect(Integer id)
     */
    public FlightTransferProtect getFlightTransferProtect(Integer id) {
        FlightTransferProtect flightTransferProtect = (FlightTransferProtect) getSqlMapClientTemplate().queryForObject("getFlightTransferProtect", id);

        //if (flightTransferProtect == null) {
            //throw new ObjectRetrievalFailureException(FlightTransferProtect.class, id);
        //}

        return flightTransferProtect;
    }

    /**
     * @see com.sasis.dao.FlightTransferProtectDao#saveFlightTransferProtect(FlightTransferProtect flightTransferProtect)
     */    
    public int saveFlightTransferProtect(final FlightTransferProtect flightTransferProtect) {
        Integer id = flightTransferProtect.getId();
        // check for new record
        if (id == null) {
            id = (Integer) getSqlMapClientTemplate().insert("addFlightTransferProtect", flightTransferProtect);
        } else {
            getSqlMapClientTemplate().update("updateFlightTransferProtect", flightTransferProtect);
        }
        if( id == null ) {
            throw new ObjectRetrievalFailureException(FlightTransferProtect.class, id);
        }
        return id.intValue();
    }

    /**
     * @see com.sasis.dao.FlightTransferProtectDao#removeFlightTransferProtect(Integer id)
     */
    public void removeFlightTransferProtect(FlightTransferProtect flightTransferProtect) {
        getSqlMapClientTemplate().update("deleteFlightTransferProtect",  flightTransferProtect);
    }
}
